package com.huawei.hwid.core.d;

import android.content.Context;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.net.Uri;
import android.text.TextUtils;
import com.huawei.hms.framework.common.ContainerUtils;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.hwid.core.constants.a.a;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.core.datatype.HwAccount;
import com.huawei.hwid.core.encrypt.b;
import com.huawei.hwid.core.encrypt.c;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import o.fup;
import o.fus;
import o.fuu;
import o.fuv;
import o.fuw;
import o.fvb;
import org.xmlpull.v1.XmlSerializer;

public class g {
    private static FileOutputStream a = null;
    private static FileInputStream b = null;
    private static Properties c = null;

    public static synchronized void a(android.content.Context r5, java.lang.String r6, java.lang.String r7) {
        /* JADX: method processing error */
/*
Error: jadx.core.utils.exceptions.JadxRuntimeException: Can't find block by offset: 0x005f in list []
	at jadx.core.utils.BlockUtils.getBlockByOffset(BlockUtils.java:42)
	at jadx.core.dex.instructions.IfNode.initBlocks(IfNode.java:60)
	at jadx.core.dex.visitors.blocksmaker.BlockFinish.initBlocksInIfNodes(BlockFinish.java:48)
	at jadx.core.dex.visitors.blocksmaker.BlockFinish.visit(BlockFinish.java:33)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:31)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:17)
	at jadx.core.ProcessClass.process(ProcessClass.java:37)
	at jadx.core.ProcessClass.processDependencies(ProcessClass.java:59)
	at jadx.core.ProcessClass.process(ProcessClass.java:42)
	at jadx.api.JadxDecompiler.processClass(JadxDecompiler.java:306)
	at jadx.api.JavaClass.decompile(JavaClass.java:62)
*/
        /*
        r1 = com.huawei.hwid.core.d.g.class;
        monitor-enter(r1);
        if (r5 == 0) goto L_0x0009;
    L_0x0005:
        if (r7 == 0) goto L_0x0009;
    L_0x0007:
        if (r6 != 0) goto L_0x0013;
    L_0x0009:
        r0 = "FileUtil";	 Catch:{ IOException -> 0x0036 }
        r2 = "at least 1 param is null";	 Catch:{ IOException -> 0x0036 }
        r3 = 1;	 Catch:{ IOException -> 0x0036 }
        com.huawei.hwid.core.d.b.e.b(r0, r2, r3);	 Catch:{ IOException -> 0x0036 }
    L_0x0011:
        monitor-exit(r1);
        return;
    L_0x0013:
        r0 = 0;
        a = r0;	 Catch:{ IOException -> 0x0036 }
        r0 = 0;	 Catch:{ IOException -> 0x0036 }
        b = r0;	 Catch:{ IOException -> 0x0036 }
        r0 = new java.util.Properties;	 Catch:{ IOException -> 0x0036 }
        r0.<init>();	 Catch:{ IOException -> 0x0036 }
        c = r0;	 Catch:{ IOException -> 0x0036 }
        b(r5, r6, r7);	 Catch:{ Exception -> 0x004d, all -> 0x007d }
        r0 = a;	 Catch:{ IOException -> 0x0043 }
        if (r0 == 0) goto L_0x002c;	 Catch:{ IOException -> 0x0043 }
    L_0x0027:
        r0 = a;	 Catch:{ IOException -> 0x0043 }
        r0.close();	 Catch:{ IOException -> 0x0043 }
    L_0x002c:
        r0 = b;	 Catch:{ IOException -> 0x0036 }
        if (r0 == 0) goto L_0x0011;	 Catch:{ IOException -> 0x0036 }
    L_0x0030:
        r0 = b;	 Catch:{ IOException -> 0x0036 }
        r0.close();	 Catch:{ IOException -> 0x0036 }
        goto L_0x0011;
    L_0x0036:
        r0 = move-exception;
        r0 = "FileUtil";	 Catch:{ IOException -> 0x0036 }
        r2 = "IOException";	 Catch:{ IOException -> 0x0036 }
        r3 = 1;	 Catch:{ IOException -> 0x0036 }
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);	 Catch:{ IOException -> 0x0036 }
        goto L_0x0011;
    L_0x0040:
        r0 = move-exception;
        monitor-exit(r1);
        throw r0;
    L_0x0043:
        r0 = move-exception;
        r0 = "FileUtil";	 Catch:{ IOException -> 0x0036 }
        r2 = "setProperties IOException";	 Catch:{ IOException -> 0x0036 }
        r3 = 1;	 Catch:{ IOException -> 0x0036 }
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);	 Catch:{ IOException -> 0x0036 }
        goto L_0x002c;
    L_0x004d:
        r0 = move-exception;
        r0 = "FileUtil";	 Catch:{ Exception -> 0x004d, all -> 0x007d }
        r2 = "IOException";	 Catch:{ Exception -> 0x004d, all -> 0x007d }
        r3 = 1;	 Catch:{ Exception -> 0x004d, all -> 0x007d }
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);	 Catch:{ Exception -> 0x004d, all -> 0x007d }
        r0 = a;
        if (r0 == 0) goto L_0x005f;
    L_0x005a:
        r0 = a;
        r0.close();
    L_0x005f:
        r0 = b;	 Catch:{ IOException -> 0x0069 }
        if (r0 == 0) goto L_0x0011;	 Catch:{ IOException -> 0x0069 }
    L_0x0063:
        r0 = b;	 Catch:{ IOException -> 0x0069 }
        r0.close();	 Catch:{ IOException -> 0x0069 }
        goto L_0x0011;
    L_0x0069:
        r0 = move-exception;
        r0 = "FileUtil";	 Catch:{ IOException -> 0x0036 }
        r2 = "IOException";	 Catch:{ IOException -> 0x0036 }
        r3 = 1;	 Catch:{ IOException -> 0x0036 }
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);	 Catch:{ IOException -> 0x0036 }
        goto L_0x0011;	 Catch:{ IOException -> 0x0036 }
    L_0x0073:
        r0 = move-exception;
        r0 = "FileUtil";
        r2 = "setProperties IOException";
        r3 = 1;
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);
        goto L_0x005f;
    L_0x007d:
        r0 = move-exception;
        r2 = a;	 Catch:{ IOException -> 0x0091 }
        if (r2 == 0) goto L_0x0087;	 Catch:{ IOException -> 0x0091 }
    L_0x0082:
        r2 = a;	 Catch:{ IOException -> 0x0091 }
        r2.close();	 Catch:{ IOException -> 0x0091 }
    L_0x0087:
        r2 = b;	 Catch:{ IOException -> 0x009b }
        if (r2 == 0) goto L_0x0090;	 Catch:{ IOException -> 0x009b }
    L_0x008b:
        r2 = b;	 Catch:{ IOException -> 0x009b }
        r2.close();	 Catch:{ IOException -> 0x009b }
    L_0x0090:
        throw r0;	 Catch:{ IOException -> 0x0036 }
    L_0x0091:
        r2 = move-exception;	 Catch:{ IOException -> 0x0036 }
        r2 = "FileUtil";	 Catch:{ IOException -> 0x0036 }
        r3 = "setProperties IOException";	 Catch:{ IOException -> 0x0036 }
        r4 = 1;	 Catch:{ IOException -> 0x0036 }
        com.huawei.hwid.core.d.b.e.d(r2, r3, r4);	 Catch:{ IOException -> 0x0036 }
        goto L_0x0087;	 Catch:{ IOException -> 0x0036 }
    L_0x009b:
        r2 = move-exception;	 Catch:{ IOException -> 0x0036 }
        r2 = "FileUtil";	 Catch:{ IOException -> 0x0036 }
        r3 = "IOException";	 Catch:{ IOException -> 0x0036 }
        r4 = 1;	 Catch:{ IOException -> 0x0036 }
        com.huawei.hwid.core.d.b.e.d(r2, r3, r4);	 Catch:{ IOException -> 0x0036 }
        goto L_0x0090;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.hwid.core.d.g.a(android.content.Context, java.lang.String, java.lang.String):void");
    }

    public static synchronized void a(android.content.Context r5, java.lang.String[] r6) {
        /* JADX: method processing error */
/*
Error: jadx.core.utils.exceptions.JadxRuntimeException: Can't find block by offset: 0x0050 in list []
	at jadx.core.utils.BlockUtils.getBlockByOffset(BlockUtils.java:42)
	at jadx.core.dex.instructions.IfNode.initBlocks(IfNode.java:60)
	at jadx.core.dex.visitors.blocksmaker.BlockFinish.initBlocksInIfNodes(BlockFinish.java:48)
	at jadx.core.dex.visitors.blocksmaker.BlockFinish.visit(BlockFinish.java:33)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:31)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:17)
	at jadx.core.ProcessClass.process(ProcessClass.java:37)
	at jadx.core.ProcessClass.processDependencies(ProcessClass.java:59)
	at jadx.core.ProcessClass.process(ProcessClass.java:42)
	at jadx.api.JadxDecompiler.processClass(JadxDecompiler.java:306)
	at jadx.api.JavaClass.decompile(JavaClass.java:62)
*/
        /*
        r1 = com.huawei.hwid.core.d.g.class;
        monitor-enter(r1);
        r0 = 0;
        a = r0;	 Catch:{ IOException -> 0x0027 }
        r0 = 0;	 Catch:{ IOException -> 0x0027 }
        b = r0;	 Catch:{ IOException -> 0x0027 }
        r0 = new java.util.Properties;	 Catch:{ IOException -> 0x0027 }
        r0.<init>();	 Catch:{ IOException -> 0x0027 }
        c = r0;	 Catch:{ IOException -> 0x0027 }
        b(r5, r6);	 Catch:{ Exception -> 0x003e, all -> 0x006e }
        r0 = a;	 Catch:{ IOException -> 0x0027 }
        if (r0 == 0) goto L_0x001c;	 Catch:{ IOException -> 0x0027 }
    L_0x0017:
        r0 = a;	 Catch:{ IOException -> 0x0027 }
        r0.close();	 Catch:{ IOException -> 0x0027 }
    L_0x001c:
        r0 = b;	 Catch:{ IOException -> 0x0034 }
        if (r0 == 0) goto L_0x0025;	 Catch:{ IOException -> 0x0034 }
    L_0x0020:
        r0 = b;	 Catch:{ IOException -> 0x0034 }
        r0.close();	 Catch:{ IOException -> 0x0034 }
    L_0x0025:
        monitor-exit(r1);
        return;
    L_0x0027:
        r0 = move-exception;
        r0 = "FileUtil";	 Catch:{ IOException -> 0x0027 }
        r2 = "removeProperties IOException:";	 Catch:{ IOException -> 0x0027 }
        r3 = 1;	 Catch:{ IOException -> 0x0027 }
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);	 Catch:{ IOException -> 0x0027 }
        goto L_0x001c;
    L_0x0031:
        r0 = move-exception;
        monitor-exit(r1);
        throw r0;
    L_0x0034:
        r0 = move-exception;
        r0 = "FileUtil";	 Catch:{ IOException -> 0x0027 }
        r2 = "IOException";	 Catch:{ IOException -> 0x0027 }
        r3 = 1;	 Catch:{ IOException -> 0x0027 }
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);	 Catch:{ IOException -> 0x0027 }
        goto L_0x0025;
    L_0x003e:
        r0 = move-exception;
        r0 = "FileUtil";	 Catch:{ Exception -> 0x003e, all -> 0x006e }
        r2 = "Exception ";	 Catch:{ Exception -> 0x003e, all -> 0x006e }
        r3 = 1;	 Catch:{ Exception -> 0x003e, all -> 0x006e }
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);	 Catch:{ Exception -> 0x003e, all -> 0x006e }
        r0 = a;
        if (r0 == 0) goto L_0x0050;
    L_0x004b:
        r0 = a;
        r0.close();
    L_0x0050:
        r0 = b;	 Catch:{ IOException -> 0x005a }
        if (r0 == 0) goto L_0x0025;	 Catch:{ IOException -> 0x005a }
    L_0x0054:
        r0 = b;	 Catch:{ IOException -> 0x005a }
        r0.close();	 Catch:{ IOException -> 0x005a }
        goto L_0x0025;
    L_0x005a:
        r0 = move-exception;
        r0 = "FileUtil";	 Catch:{ IOException -> 0x0027 }
        r2 = "IOException";	 Catch:{ IOException -> 0x0027 }
        r3 = 1;	 Catch:{ IOException -> 0x0027 }
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);	 Catch:{ IOException -> 0x0027 }
        goto L_0x0025;	 Catch:{ IOException -> 0x0027 }
    L_0x0064:
        r0 = move-exception;
        r0 = "FileUtil";
        r2 = "removeProperties IOException:";
        r3 = 1;
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);
        goto L_0x0050;
    L_0x006e:
        r0 = move-exception;
        r2 = a;	 Catch:{ IOException -> 0x0082 }
        if (r2 == 0) goto L_0x0078;	 Catch:{ IOException -> 0x0082 }
    L_0x0073:
        r2 = a;	 Catch:{ IOException -> 0x0082 }
        r2.close();	 Catch:{ IOException -> 0x0082 }
    L_0x0078:
        r2 = b;	 Catch:{ IOException -> 0x008c }
        if (r2 == 0) goto L_0x0081;	 Catch:{ IOException -> 0x008c }
    L_0x007c:
        r2 = b;	 Catch:{ IOException -> 0x008c }
        r2.close();	 Catch:{ IOException -> 0x008c }
    L_0x0081:
        throw r0;	 Catch:{ IOException -> 0x0027 }
    L_0x0082:
        r2 = move-exception;	 Catch:{ IOException -> 0x0027 }
        r2 = "FileUtil";	 Catch:{ IOException -> 0x0027 }
        r3 = "removeProperties IOException:";	 Catch:{ IOException -> 0x0027 }
        r4 = 1;	 Catch:{ IOException -> 0x0027 }
        com.huawei.hwid.core.d.b.e.d(r2, r3, r4);	 Catch:{ IOException -> 0x0027 }
        goto L_0x0078;	 Catch:{ IOException -> 0x0027 }
    L_0x008c:
        r2 = move-exception;	 Catch:{ IOException -> 0x0027 }
        r2 = "FileUtil";	 Catch:{ IOException -> 0x0027 }
        r3 = "IOException";	 Catch:{ IOException -> 0x0027 }
        r4 = 1;	 Catch:{ IOException -> 0x0027 }
        com.huawei.hwid.core.d.b.e.d(r2, r3, r4);	 Catch:{ IOException -> 0x0027 }
        goto L_0x0081;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.hwid.core.d.g.a(android.content.Context, java.lang.String[]):void");
    }

    public static boolean a(File file) {
        e.b("FileUtil", "deleteFile : file.getName", true);
        if (!file.exists()) {
            return true;
        }
        if (file.isDirectory()) {
            File[] listFiles = file.listFiles();
            if (listFiles != null) {
                for (File a : listFiles) {
                    a(a);
                }
            }
        }
        return file.delete();
    }

    public static boolean a(Context context, String str) {
        if (context == null || TextUtils.isEmpty(str)) {
            return false;
        }
        return a(new File(context.getFilesDir(), str));
    }

    public static boolean a(String str, String str2, byte[] bArr) {
        Throwable th;
        if (str == null || TextUtils.isEmpty(str) || str2 == null || TextUtils.isEmpty(str2) || bArr == null) {
            return false;
        }
        FileOutputStream fileOutputStream = null;
        try {
            File file = new File(str);
            if (file.exists() || file.mkdirs()) {
                FileOutputStream fileOutputStream2 = new FileOutputStream(new File(str + str2));
                try {
                    fileOutputStream2.write(bArr);
                    if (fileOutputStream2 != null) {
                        try {
                            fileOutputStream2.close();
                        } catch (IOException e) {
                            e.d("FileUtil", "IOException ", true);
                        }
                    }
                } catch (FileNotFoundException e2) {
                    fileOutputStream = fileOutputStream2;
                    try {
                        e.d("FileUtil", "writeAgreement FileNotFoundException", true);
                        if (fileOutputStream != null) {
                            return false;
                        }
                        try {
                            fileOutputStream.close();
                            return false;
                        } catch (IOException e3) {
                            e.d("FileUtil", "IOException ", true);
                            return false;
                        }
                    } catch (Throwable th2) {
                        th = th2;
                        if (fileOutputStream != null) {
                            try {
                                fileOutputStream.close();
                            } catch (IOException e4) {
                                e.d("FileUtil", "IOException ", true);
                            }
                        }
                        throw th;
                    }
                } catch (IOException e5) {
                    fileOutputStream = fileOutputStream2;
                    e.d("FileUtil", "writeAgreement IOException", true);
                    if (fileOutputStream != null) {
                        return false;
                    }
                    try {
                        fileOutputStream.close();
                        return false;
                    } catch (IOException e6) {
                        e.d("FileUtil", "IOException ", true);
                        return false;
                    }
                } catch (RuntimeException e7) {
                    fileOutputStream = fileOutputStream2;
                    e.d("FileUtil", "RuntimeException ", true);
                    if (fileOutputStream != null) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException e8) {
                            e.d("FileUtil", "IOException ", true);
                        }
                    }
                    return true;
                } catch (Exception e9) {
                    fileOutputStream = fileOutputStream2;
                    e.d("FileUtil", "Exception ", true);
                    if (fileOutputStream != null) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException e10) {
                            e.d("FileUtil", "IOException ", true);
                        }
                    }
                    return true;
                } catch (Throwable th3) {
                    th = th3;
                    fileOutputStream = fileOutputStream2;
                    if (fileOutputStream != null) {
                        fileOutputStream.close();
                    }
                    throw th;
                }
                return true;
            } else if (fileOutputStream == null) {
                return false;
            } else {
                try {
                    fileOutputStream.close();
                    return false;
                } catch (IOException e11) {
                    e.d("FileUtil", "IOException ", true);
                    return false;
                }
            }
        } catch (FileNotFoundException e12) {
            e.d("FileUtil", "writeAgreement FileNotFoundException", true);
            if (fileOutputStream != null) {
                return false;
            }
            fileOutputStream.close();
            return false;
        } catch (IOException e13) {
            e.d("FileUtil", "writeAgreement IOException", true);
            if (fileOutputStream != null) {
                return false;
            }
            fileOutputStream.close();
            return false;
        } catch (RuntimeException e14) {
            e.d("FileUtil", "RuntimeException ", true);
            if (fileOutputStream != null) {
                fileOutputStream.close();
            }
            return true;
        } catch (Exception e15) {
            e.d("FileUtil", "Exception ", true);
            if (fileOutputStream != null) {
                fileOutputStream.close();
            }
            return true;
        }
    }

    public static synchronized String b(Context context, String str) {
        FileInputStream openFileInput;
        FileInputStream fileInputStream;
        String str2;
        Throwable th;
        Throwable th2;
        FileOutputStream fileOutputStream = null;
        synchronized (g.class) {
            FileOutputStream fileOutputStream2;
            try {
                Properties properties = new Properties();
                if (new File(context.getFilesDir().getPath() + "/" + "settings.properties").exists()) {
                    fileOutputStream2 = null;
                } else {
                    fileOutputStream2 = context.openFileOutput("settings.properties", 0);
                }
                try {
                    openFileInput = context.openFileInput("settings.properties");
                    if (openFileInput != null) {
                        try {
                            properties.load(openFileInput);
                        } catch (FileNotFoundException e) {
                            fileOutputStream = fileOutputStream2;
                            fileInputStream = openFileInput;
                            try {
                                e.d("FileUtil", "Can not find the file settings.properties", true);
                                if (fileOutputStream != null) {
                                    try {
                                        fileOutputStream.close();
                                    } catch (IOException e2) {
                                        e.d("FileUtil", "getProperties IOException / ", true);
                                    }
                                }
                                if (fileInputStream != null) {
                                    try {
                                        fileInputStream.close();
                                    } catch (IOException e3) {
                                        e.d("FileUtil", "getProperties IOException / ", true);
                                    }
                                }
                                str2 = "";
                                return str2;
                            } catch (Throwable th3) {
                                th = th3;
                                openFileInput = fileInputStream;
                                fileOutputStream2 = fileOutputStream;
                                th2 = th;
                                if (fileOutputStream2 != null) {
                                    try {
                                        fileOutputStream2.close();
                                    } catch (IOException e4) {
                                        e.d("FileUtil", "getProperties IOException / ", true);
                                    }
                                }
                                if (openFileInput != null) {
                                    try {
                                        openFileInput.close();
                                    } catch (IOException e5) {
                                        e.d("FileUtil", "getProperties IOException / ", true);
                                    }
                                }
                                throw th2;
                            }
                        } catch (Throwable th4) {
                            th2 = th4;
                            if (fileOutputStream2 != null) {
                                fileOutputStream2.close();
                            }
                            if (openFileInput != null) {
                                openFileInput.close();
                            }
                            throw th2;
                        }
                    }
                    e.b("FileUtil", "getProperties inStream is null", true);
                    str2 = properties.getProperty(str);
                    if (TextUtils.isEmpty(str2)) {
                        if (fileOutputStream2 != null) {
                            try {
                                fileOutputStream2.close();
                            } catch (IOException e6) {
                                e.d("FileUtil", "getProperties IOException / ", true);
                            }
                        }
                        if (openFileInput != null) {
                            try {
                                openFileInput.close();
                            } catch (IOException e7) {
                                e.d("FileUtil", "getProperties IOException / ", true);
                            }
                        }
                    } else {
                        for (Object equals : a.a()) {
                            if (str.equals(equals)) {
                                str2 = c.c(context, str2);
                                break;
                            }
                        }
                        if (fileOutputStream2 != null) {
                            try {
                                fileOutputStream2.close();
                            } catch (IOException e8) {
                                e.d("FileUtil", "getProperties IOException / ", true);
                            }
                        }
                        if (openFileInput != null) {
                            try {
                                openFileInput.close();
                            } catch (IOException e9) {
                                e.d("FileUtil", "getProperties IOException / ", true);
                            }
                        }
                    }
                } catch (FileNotFoundException e10) {
                    FileOutputStream fileOutputStream3 = fileOutputStream2;
                    fileInputStream = null;
                    fileOutputStream = fileOutputStream3;
                    e.d("FileUtil", "Can not find the file settings.properties", true);
                    if (fileOutputStream != null) {
                        fileOutputStream.close();
                    }
                    if (fileInputStream != null) {
                        fileInputStream.close();
                    }
                    str2 = "";
                    return str2;
                } catch (Throwable th32) {
                    th = th32;
                    openFileInput = null;
                    th2 = th;
                    if (fileOutputStream2 != null) {
                        fileOutputStream2.close();
                    }
                    if (openFileInput != null) {
                        openFileInput.close();
                    }
                    throw th2;
                }
            } catch (FileNotFoundException e11) {
                fileInputStream = null;
                e.d("FileUtil", "Can not find the file settings.properties", true);
                if (fileOutputStream != null) {
                    fileOutputStream.close();
                }
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
                str2 = "";
                return str2;
            } catch (Throwable th5) {
                openFileInput = null;
                th2 = th5;
                fileOutputStream2 = null;
                if (fileOutputStream2 != null) {
                    fileOutputStream2.close();
                }
                if (openFileInput != null) {
                    openFileInput.close();
                }
                throw th2;
            }
        }
        return str2;
    }

    private static void b(Context context, String str, String str2) throws Exception {
        int i = 0;
        File filesDir = context.getFilesDir();
        if (filesDir != null && filesDir.getPath() != null) {
            if (new File(filesDir.getPath() + "/" + "settings.properties").exists()) {
                b = context.openFileInput("settings.properties");
                if (b != null) {
                    c.load(b);
                } else {
                    e.b("FileUtil", "inStream is null", true);
                }
            }
            a = context.openFileOutput("settings.properties", 0);
            String[] a = a.a();
            int length = a.length;
            while (i < length) {
                if (str.equals(a[i])) {
                    str2 = c.b(context, str2);
                    break;
                }
                i++;
            }
            c.setProperty(str, str2);
            if (a != null) {
                c.store(a, "accountagent");
            } else {
                e.b("FileUtil", "outStream is null", true);
            }
        }
    }

    private static void b(Context context, String[] strArr) throws Exception {
        int i = 0;
        if (new File(context.getFilesDir().getPath() + "/" + "settings.properties").exists()) {
            b = context.openFileInput("settings.properties");
            if (b != null) {
                c.load(b);
            } else {
                e.b("FileUtil", "inStream is null", true);
            }
        }
        a = context.openFileOutput("settings.properties", 0);
        if (strArr != null && strArr.length > 0) {
            int length = strArr.length;
            while (i < length) {
                Object obj = strArr[i];
                if (obj != null) {
                    c.remove(obj);
                }
                i++;
            }
        }
        if (a != null) {
            c.store(a, "accountagent");
        } else {
            e.b("FileUtil", "outStream is null", true);
        }
    }

    public static void a(XmlSerializer xmlSerializer, String str, String str2) {
        try {
            xmlSerializer.startTag("", str);
            xmlSerializer.text(str2);
            xmlSerializer.endTag("", str);
        } catch (IllegalArgumentException e) {
            e.d("FileUtil", "IllegalArgumentException  ", true);
        } catch (IllegalStateException e2) {
            e.d("FileUtil", "IllegalStateException ", true);
        } catch (IOException e3) {
            e.d("FileUtil", "IOException ", true);
        } catch (Exception e4) {
            e.d("FileUtil", "Exception ", true);
        }
    }

    public static void a(Context context, String str, fus.a aVar) {
        HwAccount a = com.huawei.hwid.c.a.a(context).a(context, str, null);
        if (a != null) {
            Object g = a.g();
            String d = a.d();
            Object a2 = com.huawei.hwid.d.a.a(context).a(d);
            if (TextUtils.isEmpty(d) || TextUtils.isEmpty(g)) {
                e.b("FileUtil", "token or userId is null", true);
                return;
            }
            String str2 = System.currentTimeMillis() + ":" + new SecureRandom().nextInt(1000);
            String str3 = "";
            if (!TextUtils.isEmpty(com.huawei.hwid.core.b.a.a.a())) {
                str3 = com.huawei.hwid.core.b.a.a.a().substring(com.huawei.hwid.core.b.a.a.a().lastIndexOf("/") + 1).replace("?Version=27120", "");
            }
            aVar.ˋ("Authorization", "Digest user=" + d + "," + "nonce" + ContainerUtils.KEY_VALUE_DELIMITER + str2 + "," + "response" + ContainerUtils.KEY_VALUE_DELIMITER + b.a(str2 + ":" + str3, g));
            if (!TextUtils.isEmpty(a2)) {
                aVar.ˋ(HwAccountConstants.EXTRA_COOKIE, a2);
                return;
            }
            return;
        }
        e.b("FileUtil", "account is null", true);
    }

    public static String a(Context context, File file, String str, HashMap<String, String> hashMap, String str2) {
        e.b("FileUtil", "begin to upLoad photo", true);
        StringBuffer stringBuffer = new StringBuffer();
        try {
            fuw a = a(file, (HashMap) hashMap);
            if (a == null) {
                e.c("FileUtil", "param is null or not enough", true);
                return stringBuffer.toString();
            }
            URL url = new URL(str);
            String replace = str.replace(url.getFile(), "");
            e.b("FileUtil", "host: " + url.getHost(), false);
            e.b("FileUtil", "File Url: " + url.getFile(), false);
            e.b("FileUtil", "baseUrl: " + replace, false);
            fus.a ˋ = new fus.a().ˎ(str).ˋ(a);
            a(context, str2, ˋ);
            fuv b = com.huawei.hwid.e.a.b(context, str, 25);
            e.b("FileUtil", "requestURL: " + str, false);
            fvb execute = b.ˎ(ˋ.ॱ()).execute();
            if (200 == execute.ˊ()) {
                stringBuffer.append(new String(execute.ᐝ().ॱ(), "UTF-8"));
            }
            return stringBuffer.toString();
        } catch (MalformedURLException e) {
            e.d("FileUtil", "upload photo failed, MalformedURLException ", true);
        } catch (IOException e2) {
            e.d("FileUtil", "upload photo failed, IOException ", true);
        }
    }

    public static Intent a(String str, Intent intent) {
        e.a("FileUtil", "begin to put  result string To intent", true);
        try {
            if (TextUtils.isEmpty(str)) {
                e.c("FileUtil", "string is empty", true);
                return null;
            }
            for (String split : str.split(ContainerUtils.FIELD_DELIMITER)) {
                String[] split2 = split.split(ContainerUtils.KEY_VALUE_DELIMITER);
                if (split2.length > 1) {
                    intent.putExtra(split2[0], split2[1]);
                }
            }
            return intent;
        } catch (RuntimeException e) {
            e.d("FileUtil", "put  result string To intent occur RuntimeException", true);
            return intent;
        } catch (Exception e2) {
            e.d("FileUtil", "put  result string To intent occur ", true);
            return intent;
        }
    }

    private static fuu a(File file, HashMap<String, String> hashMap) {
        if (file == null || !file.isFile() || hashMap == null || hashMap.isEmpty() || hashMap.entrySet().size() < 4) {
            e.c("FileUtil", "init body failed", true);
            return null;
        }
        Set<Entry> entrySet = hashMap.entrySet();
        e.a("FileUtil", "begin to init body", true);
        fuu.e ˏ = new fuu.e().ˏ(fuu.ˋ);
        for (Entry entry : entrySet) {
            ˏ.ॱ((String) entry.getKey(), (String) entry.getValue());
        }
        ˏ.ˊ("BigImage", file.getName(), fuw.create(fup.ॱ("image/*"), file));
        return ˏ.ˎ();
    }

    public static boolean a(Context context, Uri uri, Uri uri2, boolean z) {
        AssetFileDescriptor openAssetFileDescriptor;
        FileOutputStream fileOutputStream;
        Throwable th;
        Object obj;
        InputStream inputStream = null;
        try {
            openAssetFileDescriptor = context.getContentResolver().openAssetFileDescriptor(uri2, "rw");
            if (openAssetFileDescriptor == null || uri2 == null || uri == null) {
                fileOutputStream = inputStream;
            } else {
                try {
                    fileOutputStream = openAssetFileDescriptor.createOutputStream();
                    try {
                        inputStream = context.getContentResolver().openInputStream(uri);
                        byte[] bArr = new byte[16384];
                        if (inputStream != null) {
                            while (true) {
                                int read = inputStream.read(bArr);
                                if (read <= 0) {
                                    break;
                                }
                                fileOutputStream.write(bArr, 0, read);
                            }
                        }
                    } catch (IOException e) {
                        if (inputStream != null) {
                            try {
                                inputStream.close();
                            } catch (IOException e2) {
                                e.b("FileUtil", "error e", true);
                                return false;
                            }
                        }
                        if (fileOutputStream != null) {
                            fileOutputStream.close();
                        }
                        context.getContentResolver().delete(uri, "", new String[0]);
                        if (openAssetFileDescriptor != null) {
                            openAssetFileDescriptor.close();
                        }
                        return false;
                    } catch (Throwable th2) {
                        th = th2;
                        if (inputStream != null) {
                            try {
                                inputStream.close();
                            } catch (IOException e3) {
                                e.b("FileUtil", "error e", true);
                                throw th;
                            }
                        }
                        if (fileOutputStream != null) {
                            fileOutputStream.close();
                        }
                        context.getContentResolver().delete(uri, "", new String[0]);
                        if (openAssetFileDescriptor != null) {
                            openAssetFileDescriptor.close();
                        }
                        throw th;
                    }
                } catch (IOException e4) {
                    obj = inputStream;
                    if (inputStream != null) {
                        inputStream.close();
                    }
                    if (fileOutputStream != null) {
                        fileOutputStream.close();
                    }
                    if (z && uri != null) {
                        context.getContentResolver().delete(uri, "", new String[0]);
                    }
                    if (openAssetFileDescriptor != null) {
                        openAssetFileDescriptor.close();
                    }
                    return false;
                } catch (Throwable th3) {
                    th = th3;
                    obj = inputStream;
                    if (inputStream != null) {
                        inputStream.close();
                    }
                    if (fileOutputStream != null) {
                        fileOutputStream.close();
                    }
                    if (z && uri != null) {
                        context.getContentResolver().delete(uri, "", new String[0]);
                    }
                    if (openAssetFileDescriptor != null) {
                        openAssetFileDescriptor.close();
                    }
                    throw th;
                }
            }
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e5) {
                    e.b("FileUtil", "error e", true);
                    return true;
                }
            }
            if (fileOutputStream != null) {
                fileOutputStream.close();
            }
            if (z && uri != null) {
                context.getContentResolver().delete(uri, "", new String[0]);
            }
            if (openAssetFileDescriptor == null) {
                return true;
            }
            openAssetFileDescriptor.close();
            return true;
        } catch (IOException e6) {
            Object obj2 = inputStream;
            obj = inputStream;
            if (inputStream != null) {
                inputStream.close();
            }
            if (fileOutputStream != null) {
                fileOutputStream.close();
            }
            context.getContentResolver().delete(uri, "", new String[0]);
            if (openAssetFileDescriptor != null) {
                openAssetFileDescriptor.close();
            }
            return false;
        } catch (Throwable th4) {
            th = th4;
            openAssetFileDescriptor = inputStream;
            fileOutputStream = inputStream;
            if (inputStream != null) {
                inputStream.close();
            }
            if (fileOutputStream != null) {
                fileOutputStream.close();
            }
            context.getContentResolver().delete(uri, "", new String[0]);
            if (openAssetFileDescriptor != null) {
                openAssetFileDescriptor.close();
            }
            throw th;
        }
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static int c(android.content.Context r6, java.lang.String r7) {
        /*
        r0 = 0;
        r5 = 1;
        if (r6 == 0) goto L_0x000a;
    L_0x0004:
        r1 = android.text.TextUtils.isEmpty(r7);
        if (r1 == 0) goto L_0x0012;
    L_0x000a:
        r1 = "FileUtil";
        r2 = "getXmlVersionCode context is null or xmlStr is empty";
        com.huawei.hwid.core.d.b.e.b(r1, r2, r5);
    L_0x0011:
        return r0;
    L_0x0012:
        r1 = "UTF-8";
        r1 = r7.getBytes(r1);	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        r2 = com.huawei.hwid.core.d.p.a(r1);	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        r1 = r2.getEventType();	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
    L_0x0020:
        if (r5 == r1) goto L_0x0011;
    L_0x0022:
        r3 = r2.getName();	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        r4 = 2;
        if (r4 != r1) goto L_0x0095;
    L_0x0029:
        r1 = "Infos";
        r1 = r1.equals(r3);	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        if (r1 == 0) goto L_0x0095;
    L_0x0031:
        r1 = r0;
    L_0x0032:
        r3 = r2.getAttributeCount();	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        if (r1 >= r3) goto L_0x0095;
    L_0x0038:
        r3 = "version-code";
        r4 = r2.getAttributeName(r1);	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        r3 = r3.equals(r4);	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        if (r3 == 0) goto L_0x0092;
    L_0x0044:
        r1 = r2.getAttributeValue(r1);	 Catch:{ Exception -> 0x004d, UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd }
        r0 = com.huawei.hwid.f.g.a(r1);	 Catch:{ Exception -> 0x004d, UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd }
        goto L_0x0011;
    L_0x004d:
        r1 = move-exception;
        r2 = "FileUtil";
        r3 = new java.lang.StringBuilder;	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        r3.<init>();	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        r4 = "e = ";
        r3 = r3.append(r4);	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        r1 = r1.getClass();	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        r1 = r1.getSimpleName();	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        r1 = r3.append(r1);	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        r1 = r1.toString();	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        r3 = 1;
        com.huawei.hwid.core.d.b.e.b(r2, r1, r3);	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        goto L_0x0011;
    L_0x0070:
        r1 = move-exception;
        r2 = "FileUtil";
        r3 = new java.lang.StringBuilder;
        r3.<init>();
        r4 = "UnsupportedEncodingException ";
        r3 = r3.append(r4);
        r1 = r1.getClass();
        r1 = r1.getSimpleName();
        r1 = r3.append(r1);
        r1 = r1.toString();
        com.huawei.hwid.core.d.b.e.c(r2, r1, r5);
        goto L_0x0011;
    L_0x0092:
        r1 = r1 + 1;
        goto L_0x0032;
    L_0x0095:
        r1 = r2.next();	 Catch:{ UnsupportedEncodingException -> 0x0070, IOException -> 0x009a, XmlPullParserException -> 0x00bd, Exception -> 0x00e0 }
        goto L_0x0020;
    L_0x009a:
        r1 = move-exception;
        r2 = "FileUtil";
        r3 = new java.lang.StringBuilder;
        r3.<init>();
        r4 = "IOException ";
        r3 = r3.append(r4);
        r1 = r1.getClass();
        r1 = r1.getSimpleName();
        r1 = r3.append(r1);
        r1 = r1.toString();
        com.huawei.hwid.core.d.b.e.c(r2, r1, r5);
        goto L_0x0011;
    L_0x00bd:
        r1 = move-exception;
        r2 = "FileUtil";
        r3 = new java.lang.StringBuilder;
        r3.<init>();
        r4 = "XmlPullParserException ";
        r3 = r3.append(r4);
        r1 = r1.getClass();
        r1 = r1.getSimpleName();
        r1 = r3.append(r1);
        r1 = r1.toString();
        com.huawei.hwid.core.d.b.e.c(r2, r1, r5);
        goto L_0x0011;
    L_0x00e0:
        r1 = move-exception;
        r2 = "FileUtil";
        r3 = new java.lang.StringBuilder;
        r3.<init>();
        r4 = "Exception ";
        r3 = r3.append(r4);
        r1 = r1.getClass();
        r1 = r1.getSimpleName();
        r1 = r3.append(r1);
        r1 = r1.toString();
        com.huawei.hwid.core.d.b.e.c(r2, r1, r5);
        goto L_0x0011;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.hwid.core.d.g.c(android.content.Context, java.lang.String):int");
    }
}
